<template>
    <a-modal v-model:visible="geSHow" title="个人简介上传" :width="850" @ok="geOk" :destroyOnClose="true" :z-index="20" @cancel="outGe">
        <div style="margin-bottom:20px;font-size:16px">
            <span style="color:#333;margin-right:10px">当前个人简介状态：</span>
            <template v-if="techGe?.blurb">
                <span :style="{ color: share.getExamineState(techGe.examine)[1] }">{{
                    share.getExamineState(techGe.examine)[0] }}</span>
            </template>
            <span v-else style="color:gray">未上传简介</span>
        </div>
        <a-textarea v-model:value="geText" placeholder="请输入个人简介 不能带有特殊字符|" :rows="5" />
    </a-modal>
</template>

<!-- 技师个人简介模块 -->
<script setup>
import { ref, defineProps, defineEmits, watch } from 'vue';
import { techStatAPI } from '../../../../api/management';
import { useUserData } from '../../../../stores/userData';
import { message } from 'ant-design-vue';
import share from '../../../../util/commnet'

const store = useUserData();    //pinia

const techGe = ref({});             //获取当前审核相信
const geSHow = ref(false);          //是否打开模块
const geText = ref('');             //简介内容

const emit = defineEmits(['setShow'])       //关闭组件的方法
const pros = defineProps({
    uid:{                       //拿到uid
        type:String,
        default:''
    },
    shows:{                     //是否关闭组件
        type:Boolean,
        default:false
    }
})


watch(                              //监听是否关闭个人简介模块
    ()=>pros.shows,
    async(n,o)=>{
        if(n && pros.uid){                      //当需要显示模块且存在uid时 拉取数据
            geText.value = '';
            let res = await techStatAPI(`geSel|${pros.uid}|${store.data.token}|${store.data.uuid}|${store.data.phone}`);    
            console.log(res);
            if (!res || res.code == 406) {
                message.error("账号失效");
                router.replace({ name: 'login' });
                return;
            } else if (res.code != 200) {
                message.error(res.message);
                return
            }
            techGe.value = res.data[0];
            if (res?.data[0]?.blurb) {
                geText.value = res.data[0].blurb;
            }
            geSHow.value = true;
        }
        geSHow.value = n;
    }
)

const geOk = async () => {
    if (geText.value.includes("|")) {
        message.error("含有违法字符|");
        return;
    }
    if (geText.value.trim().length == 0) {
        message.error("请输入内容");
        return;
    }
    let res = await techStatAPI(`geUp|${pros.uid}|${geText.value}|${store.data.token}|${store.data.uuid}|${store.data.phone}`);
    if (!res || res.code == 406) {
        message.error("账号失效");
        router.replace({ name: 'login' });
        return;
    } else if (res.code != 200) {
        message.error(res.message);
        return
    }
    message.success("添加成功")
    emit('setShow',false) 
}


const outGe= ()=>{               //当点击蒙层或者取消时
    emit('setShow',false)           //传递父组件关闭
}
</script>